import 'package:flutter/foundation.dart';
import 'package:lib_core/lib_core.dart';
import 'package:lib_core/logger/gt_logger_model.dart';

import './gt_logger_base_destination.dart';

/// Author: Shper
/// Created: 2024/2/01
class GTLoggerConsoleDestination extends GTLoggerBaseDestination {
  @override
  bool ignoreLog(GTLoggerModel logModel) {
    // 发版包，控制台忽略 INFO、DEBUG、VERBOSE 级别日志
    if (GTLibCore.globalConfig.publishBuild && logModel.level.index <= GTLoggerLevel.info.index) {
      return true;
    }
    // 默认不忽略
    return false;
  }

  @override
  void handleLog(GTLoggerModel logModel) {
    // _LoggerTestPageState.testLog (package:lib_core_example/logger_test_page.dart:43:14)
    // 控制台打印, [级别] 函数名:(文件名:行号) - 日志内容
    final message = "[${logModel.level.shortName}] ${logModel.funcName}(${logModel.fileName}:${logModel.lineNo}) - ${logModel.message}";
    // Android logcat 不支持ANSI颜色
    // if(Platform.isAndroid) {
    //   debugPrint(message);
    // } else {
    //   var color = getLevelColor(logModel.level);
    //   debugPrint(color(message));
      debugPrint(message);
    // }
  }
}
